package com.hnas.trade.dao.impl;

import java.util.List;

import org.apache.commons.beanutils.BeanUtils;
import org.springframework.stereotype.Component;

import com.hnas.core.dao.BaseDaoImpl;
import com.hnas.trade.dao.CheckOrderRecordDao;
import com.hnas.trade.orm.CheckOrderRecord;

@Component("checkOrderRecordDao")
public class CheckOrderRecordDaoImpl extends BaseDaoImpl<CheckOrderRecord> implements CheckOrderRecordDao{

	public CheckOrderRecordDaoImpl() {
		super(CheckOrderRecord.class);
	}

	@Override
	public CheckOrderRecord saveOrUpdate(CheckOrderRecord vo) throws Exception {
		CheckOrderRecord record = this.entityManager.find(CheckOrderRecord.class, vo.getId());
		if(record == null){
			record = new CheckOrderRecord();
			BeanUtils.copyProperties(record, vo);
			this.entityManager.persist(record);
		}else{
			BeanUtils.copyProperties(record, vo);
			this.entityManager.merge(record);
		}
		return record;
	}

	@Override
	public CheckOrderRecord findByOrderNo(String orderNo) {
		String hql = "from CheckOrderRecord t where t.orderNo = ?1";
		List<CheckOrderRecord> list = this.findByQuery(hql, orderNo);
		if(list != null && list.size() > 0){
			return list.get(0);
		}
		return null;
	}

}
